package com.ufgov.agcfs.baseData.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import uap.iweb.entity.DataTable;
import uap.iweb.exception.WebRuntimeException;
import uap.iweb.icontext.IWebViewContext;

import com.ufgov.agcfs.baseData.entity.ReportType;
import com.ufgov.agcfs.baseData.service.ReportTypeService;
import com.ufgov.ip.entity.IpUser;

@Controller("baseData.reportType.reportTypeController")
@Scope("prototype")
@RequestMapping(value = "baseData.reportType")
public class ReportTypeController {
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private ReportTypeService reportService;
	
	DataTable<IpUser> reportTypeDataTable;
	
	public void loadReportType() {
		try {
//			Map<String, Object> searchParams = new HashMap<String, Object>();
//			searchParams = iPDataTableService.createSearchParamsStartingWith("search_",userDataTable);
//			Sort sort = iPDataTableService.buildSortRequest(Direction.ASC, "theCode");

			List<ReportType> categoryPage = reportService.findAll();
			reportTypeDataTable.remove(reportTypeDataTable.getAllRow());
			reportTypeDataTable.set(categoryPage.toArray(new ReportType[0]));
			IWebViewContext.getResponse().write("true");
		} catch (Exception e) {
			IWebViewContext.getResponse().write("false");
			throw new WebRuntimeException("数据读取失败.");
		}
	}
}
